package com.sanpu.kxe.business.main.adapter;

import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sanpu.kxe.R;
import com.sanpu.kxe.business.main.bean.PartnerAllyOutput;
import com.sanpu.kxe.common.enums.Level;
import com.sanpu.kxe.common.utils.CommonUtils;
import com.sanpu.kxe.module.roundview.RoundLinearLayout;
import com.sanpu.kxe.module.roundview.RoundTextView;

import java.util.ArrayList;

/**
 * Description：合伙人团队详情
 * Created by 薛勇军 on 2018/8/6.
 */

public class PartnerTeamAdapter extends BaseQuickAdapter<PartnerAllyOutput, BaseViewHolder> {

    public PartnerTeamAdapter() {
        super(R.layout.item_team, new ArrayList<PartnerAllyOutput>());
    }

    @Override
    protected void convert(BaseViewHolder helper, PartnerAllyOutput item) {
        if (item != null) {
            helper.setText(R.id.count, "推荐人数" + item.getRefCount() + "")
                    .setText(R.id.amount, Html.fromHtml("佣金奖励 <font color='#FF9F23'>" +
                            item.getAccRebAmt() + "</font>元"))
                    .setText(R.id.level, CommonUtils.getLevelName(item.getUserLvl()))
                    .setVisible(R.id.item_arrow, false);

            TextView uName = helper.getView(R.id.name);
            RoundTextView vAuthFlag = helper.getView(R.id.auth_flag);
            if (item.getRlAuthFlg() == 2) {
                if (!TextUtils.isEmpty(item.getuName())) {
                    uName.setText(item.getuName());
                }
                vAuthFlag.setVisibility(View.VISIBLE);
                vAuthFlag.setText("已认证");
            } else {
                uName.setText(String.valueOf(item.getuAccountName() + ""));
                vAuthFlag.setVisibility(View.GONE);
            }

            RoundLinearLayout vLevelLayout = helper.getView(R.id.level_layout);
            try {
                Level level = Level.values()[item.getUserLvl() - 1];
                vLevelLayout.setVisibility(item.getUserLvl() > 1 ? View.VISIBLE : View.GONE);
                vLevelLayout.getDelegate().setBackgroundColor(ContextCompat.getColor(mContext, level.getColorRes()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
